package cn.jsj.dispose;

import cn.jsj.pojo.TblAdminPersonnel;
import cn.jsj.pojo.TblLawyAssistant;
import cn.jsj.pojo.TblLawyer;
import cn.jsj.pojo.TblPracticeLawyer;

/**
 * 登陆处理类
 *
 * @author LI
 *
 */
public class LoginDispose {

	/**
	 * 登陆验证
	 *
	 * @param userName：用户名
	 * @param pwd：密码
	 * @param role：角色
	 * @return：登陆结果 error:不存在用户 ok:登陆成功 exception：异常
	 */
	public String loginValidate(String userName, String pwd, String role) {

		//调试信息
		cn.jsj.utils.SysLogger.PrintInfo("name----------->"+userName+pwd+role);

		//如果为律师
		if(role.equals("1")){
			//新建一个律师对象
			cn.jsj.pojo.TblLawyer lawyer=new cn.jsj.pojo.TblLawyer();
			lawyer.setLawyerName(userName);
			lawyer.setLawyerPwd(pwd);

			//验证该律师是否存在
			cn.jsj.dao.TblLawyerDAO tld=new cn.jsj.dao.TblLawyerDAO();
			TblLawyer destLawyer=tld.userValidate(lawyer);

			//如果存在
			if(destLawyer!=null){
				//获得session对象
				cn.jsj.utils.GetWebSession gws=new cn.jsj.utils.GetWebSession();
				javax.servlet.http.HttpSession session=	gws.getSession();

				//保存"全局变量"
				session.setAttribute("userId", destLawyer.getLawyerId());
				session.setAttribute("userName", destLawyer.getLawyerName());
				session.setAttribute("popedomLevel", destLawyer.getPopedomLevel());
				session.setAttribute("role", 1);
				session.setAttribute("roleName", "律师");


				//返回ok
				return "ok";
		}else{
			//不存在该律师
			return "error";
		}
	}

			//如果为行政人员
			if(role.equals("4")){
				//新建一个行政人员对象
				TblAdminPersonnel tap=new TblAdminPersonnel();
				tap.setAdminPersonName(userName);
				tap.setLawyerPwd(pwd);

				//验证该行政人员是否存在
				cn.jsj.dao.TblAdminPersonnelDAO tapd=new cn.jsj.dao.TblAdminPersonnelDAO();
				TblAdminPersonnel destTap=tapd.userValidate(tap);

				//如果存在
				if(destTap!=null){
					//获得session对象
					cn.jsj.utils.GetWebSession gws=new cn.jsj.utils.GetWebSession();
					javax.servlet.http.HttpSession session=	gws.getSession();

					//保存"全局变量"
					session.setAttribute("userId", destTap.getAdminPersonId());
					session.setAttribute("userName", destTap.getAdminPersonName());
					session.setAttribute("popedomLevel", destTap.getPopedomLevel());
					session.setAttribute("role", 3);
					session.setAttribute("roleName", "行政人员");

					//返回ok
					return "ok";
				}
					//不存在该行政人员
					return "error";
			}

			//异常情况
			return "exception";
		}
}
